package jackie.testJVM;

import java.util.ArrayList;
import java.util.List;

/**
 *  Java堆内存溢出
 * Created by jackie on 2016/8/11.
 */
public class TestJVMOOM {

    /**
     * -Xms20M -Xmx20M -Xmn10M -XX:SurvivorRatio=8 -XX:PermSize=32M -XX:MaxPermSize=64M -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError
     */
    public static void main(String[] args) throws InterruptedException {
        List<OOMObject> list = new ArrayList<OOMObject>();
        int count = 0;
        Thread.sleep(2000);
        while(true){
            try {
                count++;
//                new jackie.testJVM.OOMObject();
                list.add(new OOMObject());
                System.out.println("共构造了"+count+"个对象");
                Thread.sleep(1);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

class OOMObject{
    int a=10;
    String s= "ss";
}